package edu.towson.cosc603.coffeemaker;

import org.junit.Before;
import org.junit.Test;

import junit.framework.TestCase;

/**
 *
 */
public class CoffeeMakerTest extends TestCase {
	private CoffeeMaker cm;
	private Inventory i;
	private Recipe r1, r2, r3;
	private Main main;

	@Before
	public void setUp() {
		cm = new CoffeeMaker();
		i = cm.checkInventory();

		r1 = new Recipe();
		r1.setName("Coffee");
		r1.setPrice(50);
		r1.setAmtCoffee(6);
		r1.setAmtMilk(1);
		r1.setAmtSugar(1);
		r1.setAmtChocolate(0);
		
		r2 = new Recipe();
		r2.setName("Tea");
		r2.setPrice(1);
		r2.setAmtCoffee(0);
		r2.setAmtMilk(0);
		r2.setAmtSugar(0);
		r2.setAmtChocolate(0);
		
		r3 = new Recipe();
		r3.setName("Hot Chocolate");
		r3.setPrice(1);
		r3.setAmtCoffee(1);
		r3.setAmtMilk(1);
		r3.setAmtSugar(1);
		r3.setAmtChocolate(1);
	}

	@Test
	public void testAddRecipe1() {
		assertTrue(cm.addRecipe(r1));
	}

	@Test
	public void testDeleteRecipe1() {
		cm.addRecipe(r1);
		assertTrue(cm.deleteRecipe(r1));
	}

	@Test
	public void testEditRecipe1() {
		cm.addRecipe(r1);
		Recipe newRecipe = new Recipe();
		newRecipe = r1;
		newRecipe.setAmtSugar(2);
		assertTrue(cm.editRecipe(r1, newRecipe));
	}
	
	@Test
	public void testCheckOptions() {
		assertEquals(Main.getMenuOptions(), "1. Add a recipe\n"
		        + "2. Delete a recipe\n"
		        + "3. Edit a recipe\n"
		        + "4. Add inventory\n"
		        + "5. Check inventory\n"
		        + "6. Purchase Beverage\n"
		        + "0. Exit\n");
	}
	
	@Test
	public void testAddInventory1() {
		assertTrue(cm.addInventory(1, 1, 1, 1));
	}
	
	@Test
	public void testCheckInventory() {
		int initialCount = 15;
        assertEquals(i.toString(), "Coffee: " + initialCount + "\n" +
    			"Milk: " + initialCount + "\n" +
    			"Sugar: " + initialCount + "\n" +
    			"Chocolate: " + initialCount + "\n");
	}
	
	@Test
	public void testPurchaseBeverage() {
		assertEquals(0, cm.makeCoffee(r1, 50));
	}
	
	@Test
	public void testAddExistingRecipe () {
		assertTrue(cm.addRecipe(r1));
		
		Recipe r2 = new Recipe();
		r2.setName("Coffee");
		assertFalse(cm.addRecipe(r2));
	}
	
	@Test
	public void testAddRecipeToFullMenu () {
		assertTrue(cm.addRecipe(r1));
		
		Recipe r2 = new Recipe();
		r2.setName("Coffee 1");
		assertTrue(cm.addRecipe(r2));
		
		r2 = new Recipe();
		r2.setName("Coffee 2");
		assertTrue(cm.addRecipe(r2));
		
		r2 = new Recipe();
		r2.setName("Coffee 3");
		assertTrue(cm.addRecipe(r2));
		
		r2 = new Recipe();
		r2.setName("Coffee 4");
		assertFalse(cm.addRecipe(r2));
	}
	
	@Test
	public void testGetRecipeForName () {
		Recipe r2 = new Recipe();
		r2.setName("Coffee 1");
		cm.addRecipe(r2);
		assertEquals(r2, cm.getRecipeForName("Coffee 1"));
	}
	
	@Test
	public void testMakeCoffee() {
		r1 = new Recipe();
		r1.setPrice(1000);
		assertEquals(12, cm.makeCoffee(r1, 12));
	}
	
	@Test
	public void testMakeCoffeeInventory() {
		r1 = new Recipe();
		r1.setPrice(1000);
		r1.setAmtChocolate(100);
		assertEquals(12, cm.makeCoffee(r1, 12));
	}
	
	@Test
	public void testMakeCoffeeCheckInventory() {
		assertEquals(0, cm.makeCoffee(r3, 1));
		i = cm.checkInventory();
		assertEquals(14, i.getCoffee());
		assertEquals(14, i.getMilk());
		assertEquals(14, i.getSugar());
		assertEquals(14, i.getChocolate());
	}
	
	@Test
	public void testAddNegativeInventory () {
		cm.addInventory(-1, -1, -1, -1);
	}
	
	@Test
	public void testGetRecipes () {
		Recipe [] recipes = cm.getRecipes();
		for (int i = 0; i < 4; i++) {
			assertNotNull(recipes[i]);
		}
	}
	
	@Test
	public void testMakeCoffeeNoIngredients() {
		assertEquals(0, cm.makeCoffee(r2, 1));
	}
	
	@Test
	public void testAddInventory() {
		assertFalse(cm.addInventory(1, 1, 1, -1));
	}
	
	@Test
	public void testAddInventoryZero() {
		assertTrue(cm.addInventory(0, 0, 0, 0));
	}
	
	@Test
	public void testAddInventoryValues() {
		assertTrue(cm.addInventory(0, 0, 0, 0));
		i = cm.checkInventory();
		assertEquals(15, i.getCoffee());
		assertEquals(15, i.getMilk());
		assertEquals(15, i.getSugar());
		assertEquals(15, i.getChocolate());
	}
}